package com.yc.project1;

import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Objects;

/**
 * @author zwei
 * @create 2024-07-26 15:27
 */
public class App {
    public static void main(String[] args) throws InvocationTargetException, InstantiationException, IllegalAccessException {
        List<Integer> list = new ArrayList<>();
        Collections.addAll(list, 1, 4);
        trackOptions(list, Order.class);
    }

    private static void trackOptions(List<Integer> list, Class<Order> orderClass) throws InstantiationException, IllegalAccessException, InvocationTargetException {
        Object o = orderClass.newInstance();
        //利用反射取出这个  opClass中所有的方法
        Method[] methods = orderClass.getDeclaredMethods();    //不包括继承的方法
        for (int i : list) {
            for (Method m : methods) {
                Step annotation = m.getAnnotation(Step.class);
                if (annotation != null) {
                    int id = annotation.id();
                    if (i == id) {
                        String desc = annotation.desc();
                        System.out.println("获取了方法" + id + ",描述" + desc);
                        m.invoke(o);
                    }
                }
            }
        }
    }
}
